<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-date-picker v-model="query.dateBegin" format="yyyy-MM-dd" value-format="yyyy-MM-dd" clearable placeholder="开始日期" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-date-picker v-model="query.dateEnd" clearable format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="结束日期" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-select v-model="query.settleStatus" placeholder="状态" style="width: 200px;" @change="changeType">
      <el-option
        v-for="(item, i) in orderStatusArr"
        :key="i"
        :label="item.dictName"
        :value="item.dictNo"/>
    </el-select>

    <el-button class="filter-item" size="mini" type="primary" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <el-button class="filter-item" size="mini" type="primary" @click="exportExcel">导出Excel</el-button>
    <el-button class="filter-item" size="mini" type="primary" @click="check">审核</el-button>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import eForm from './form'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    },
    permissions: {
      type: Array,
      required: true
    },
    companyLevels: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      downloadLoading: false,
      companyType: "",
      orderStatusArr: []
    }
  },
  mounted() {
    this.$api.fenxiao.sysDict.findByPdictCode("SETTLE_STATUS").then(res => {
      this.orderStatusArr = res.data
    })
  },
  methods: {
    checkPermission,
    toQuery() {
      console.log(this.query)
      this.$parent.page = 0
      this.$parent.init()
    },
    changeType(e) {
      this.query.companyType = e
      // this.toQuery()
    },
    exportExcel() {
      const url = `https://jinfang.xunyu.shop/admin/settleDetail/export?dateBegin=${this.query.dateBegin || ''}&dateEnd=${this.query.dateEnd || ''}&settleStatus=${this.query.settleStatus || ''}&pageNum=${this.$parent.page}&pageSize=${this.$parent.limit}`
      window.open(url)
    },
    check() {
      const arr = []
      this.$parent.multipleSelection.forEach(v => {
        arr.push(v.id)
      });
      const obj = {
        auditActionEnum: "PASS",
        auditDesc: "",
        orderNos: arr
      }
      this.$api.fenxiao.settleTotal.check({ data: obj }).then(res => {
        this.delLoading = false
        this.$parent.init()
        this.$notify({ title: '审核成功', type: 'success', duration: 2500 })
      }).catch(err => {
        this.delLoading = false
        console.log(err.response.data.message)
      })
    },
  }
}
</script>
